package de.szut.traineeslife.adapter;

import java.io.File;
import java.util.ArrayList;

import de.szut.traineeslife.R;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FilesFromSDAdapter extends ArrayAdapter<File> {

	private Context mContext;
	private ArrayList<File> mFileList;


	/**The Adapter to Display the foundend Folders on the Sd card
	 * 
	 * @param context
	 * @param textViewResourceId
	 * @param fileList
	 */
	public FilesFromSDAdapter(Context context, int textViewResourceId, ArrayList<File> fileList) {
		super(context, textViewResourceId, fileList);
		this.mContext = context;
		this.mFileList = fileList;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		ItemView itemView = new ItemView();
		if (v == null) {
			LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inflater.inflate(R.layout.select_model_item, parent, false);
			itemView.fileName = (TextView) v.findViewById(R.id.item_name);
			v.setTag(itemView);
		} else {
			itemView = (ItemView) v.getTag();
		}
		File file = mFileList.get(position);
		if (file != null) {
			itemView.fileName.setText(file.getName());
		}
		return v;
	}
	
	private static class ItemView{
		private TextView fileName;
	}
	
	@Override
	public int getCount() {
		return mFileList.size();
	}
}
